﻿/*
COPYRIGHT (C) 2009 EPISERVER AB

THIS FILE IS PART OF REMOTE PAGE PROVIDER FOR EPISERVER CMS.
REMOTE PAGE PROVIDER FOR EPISERVER CMS IS FREE SOFTWARE: YOU CAN REDISTRIBUTE IT AND/OR MODIFY IT UNDER THE TERMS OF THE GNU LESSER GENERAL PUBLIC LICENSE VERSION v2.1 AS PUBLISHED BY THE FREE SOFTWARE FOUNDATION.

REMOTE PAGE PROVIDER FOR EPISERVER CMS IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, BUT WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. SEE THE GNU LESSER GENERAL PUBLIC LICENSE FOR MORE DETAILS.
YOU SHOULD HAVE RECEIVED A COPY OF THE GNU LESSER GENERAL PUBLIC LICENSE ALONG WITH REMOTE PAGE PROVIDER FOR EPISERVER CMS]. IF NOT, SEE <HTTP://WWW.GNU.ORG/LICENSES/>.
*/
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using EPiServer.DataAccess;
using EPiServer.DataAbstraction;
using EPiServer.Security;
using System.Security.Principal;
using System.IO;
using EPiServer.Core;

namespace EPiServer.Labs.RemoteProvider
{
    [ServiceContract(Namespace = "http://schemas.episerver.com/WCF/RemoteProvider", SessionMode= SessionMode.Required)]
    public interface IRemoteProvider
    {

        #region Page Operation 
        /// <summary>
        /// Initializes the specified initialize data.
        /// </summary>
        /// <param name="initializeData">The initialize data.</param>
        [OperationContract]
        [FaultContract(typeof(RemoteProviderFault))]
        void Initialize(ref InitializeData initializeData);

        /// <summary>
        /// Gets the children references.
        /// </summary>
        /// <param name="pageLink">The page link.</param>
        /// <returns>PageReferenceCollection which is children's pagereference</returns>
        [OperationContract]
        [FaultContract(typeof(RemoteProviderFault))]
        PageReferenceCollection GetChildrenReferences(PageReference pageLink);

        /// <summary>
        /// Gets the pages.
        /// </summary>
        /// <param name="pageLinks">The page links.</param>
        /// <param name="selector">The selector.</param>
        /// <returns> RemotePageRaw[] which is an array of light version of PageData raw data </returns>
        [OperationContract]
        [FaultContract(typeof(RemoteProviderFault))]
        RemotePageRaw[] GetPages(PageReferenceCollection pageLinks, LanguageSelector selector);

        /// <summary>
        /// Gets the page.
        /// </summary>
        /// <param name="pageLink">The page link.</param>
        /// <param name="selector">The selector.</param>
        /// <returns>RemotePageRaw which is a light version of PageData raw data</returns>
        [OperationContract]
        [FaultContract(typeof(RemoteProviderFault))]
        RemotePageRaw GetPage(PageReference pageLink, LanguageSelector selector);

        /// <summary>
        /// Finds the pages with criteria.
        /// </summary>
        /// <param name="pageLink">The page link.</param>
        /// <param name="criterias">The criterias.</param>
        /// <param name="languageBranch">The language branch.</param>
        /// <param name="selector">The selector.</param>
        /// <returns>RemotePageRaw which is a light version of PageData raw data</returns>
        [OperationContract]
        [FaultContract(typeof(RemoteProviderFault))]
        RemotePageRaw[] FindPagesWithCriteria(PageReference pageLink, PropertyCriteriaCollection criterias, string languageBranch, LanguageSelector selector);

        /// <summary>
        /// Gets the language branches.
        /// </summary>
        /// <param name="pageLink">The page link.</param>
        /// <returns>RemotePageRaw which is a light version of PageData raw data</returns>
        [OperationContract]
        [FaultContract(typeof(RemoteProviderFault))]
        RemotePageRaw[] GetLanguageBranches(PageReference pageLink);

        /// <summary>
        /// Creates the language branch.
        /// </summary>
        /// <param name="pageLink">The page link.</param>
        /// <param name="selector">The selector.</param>
        /// <returns>RemotePageRaw which is a light version of PageData raw data</returns>
        [OperationContract]
        [FaultContract(typeof(RemoteProviderFault))]
        RemotePageRaw CreateLanguageBranch(PageReference pageLink, LanguageSelector selector);

        /// <summary>
        /// Deletes the language branch.
        /// </summary>
        /// <param name="pageLink">The page link.</param>
        /// <param name="languageBranch">The language branch.</param>
        [OperationContract]
        [FaultContract(typeof(RemoteProviderFault))]
        void DeleteLanguageBranch(PageReference pageLink, string languageBranch);

        /// <summary>
        /// Deletes the version.
        /// </summary>
        /// <param name="pageLink">The page link.</param>
        [OperationContract]
        [FaultContract(typeof(RemoteProviderFault))]
        void DeleteVersion(PageReference pageLink);

        /// <summary>
        /// Deletes the specified page link.
        /// </summary>
        /// <param name="pageLink">The page link.</param>
        /// <param name="forceDelete">if set to <c>true</c> [force delete].</param>
        [OperationContract]
        [FaultContract(typeof(RemoteProviderFault))]
        void Delete(PageReference pageLink, bool forceDelete);

        /// <summary>
        /// Deletes the children.
        /// </summary>
        /// <param name="pageLink">The page link.</param>
        /// <param name="forceDelete">if set to <c>true</c> [force delete].</param>
        [OperationContract]
        [FaultContract(typeof(RemoteProviderFault))]
        void DeleteChildren(PageReference pageLink, bool forceDelete);

        /// <summary>
        /// Moves the specified page link.
        /// </summary>
        /// <param name="pageLink">The page link.</param>
        /// <param name="destinationLink">The destination link.</param>
        [OperationContract]
        [FaultContract(typeof(RemoteProviderFault))]
        void Move(PageReference pageLink, PageReference destinationLink);

        /// <summary>
        /// Moves to wastebasket.
        /// </summary>
        /// <param name="pageLink">The page link.</param>
        [OperationContract]
        [FaultContract(typeof(RemoteProviderFault))]
        void MoveToWastebasket(PageReference pageLink);

        /// <summary>
        /// Copies the specified page link.
        /// </summary>
        /// <param name="pageLink">The page link.</param>
        /// <param name="destinationLink">The destination link.</param>
        /// <param name="publishOnDestination">if set to <c>true</c> [publish on destination].</param>
        /// <param name="allowThreading">if set to <c>true</c> [allow threading].</param>
        /// <returns></returns>
        [OperationContract]
        [FaultContract(typeof(RemoteProviderFault))]
        PageReference Copy(PageReference pageLink, PageReference destinationLink, bool publishOnDestination, bool allowThreading);

        /// <summary>
        /// Saves the specified page.
        /// </summary>
        /// <param name="page">The page.</param>
        /// <param name="action">The action.</param>
        /// <returns></returns>
        /// <param name="IsModified">Indicates if the page is modified</param>
        [OperationContract]
        [FaultContract(typeof(RemoteProviderFault))]
        PageReference Save(RemotePageRaw page, int action, bool IsModified);

        /// <summary>
        /// Resolves the page from page GUID.
        /// </summary>
        /// <param name="pageGuid">The page GUID.</param>
        /// <param name="pageLink">The page link.</param>
        /// <returns>PageTypeName</returns>
        [OperationContract]
        [FaultContract(typeof(RemoteProviderFault))]
        string ResolvePageFromPageGuid(Guid pageGuid, out PageReference pageLink);

        /// <summary>
        /// Resolves the page from page link.
        /// </summary>
        /// <param name="pageLink">The page link.</param>
        /// <param name="pageGuid">The page GUID.</param>
        /// <returns>PageTypeName</returns>
        [OperationContract]
        [FaultContract(typeof(RemoteProviderFault))]
        string ResolvePageFromPageLink(PageReference pageLink, out Guid pageGuid);

        /// <summary>
        /// Lists the versions.
        /// </summary>
        /// <param name="pageLink">The page link.</param>
        /// <param name="languageBranch">The language branch.</param>
        /// <returns></returns>
        [OperationContract]
        [FaultContract(typeof(RemoteProviderFault))]
        PageVersionCollection ListVersions(PageReference pageLink, string languageBranch);

        /// <summary>
        /// Lists the published versions.
        /// </summary>
        /// <param name="pageLink">The page link.</param>
        /// <returns></returns>
        [OperationContract]
        [FaultContract(typeof(RemoteProviderFault))]
        PageVersionCollection ListPublishedVersions(PageReference pageLink);

        /// <summary>
        /// Loads the version.
        /// </summary>
        /// <param name="pageLink">The page link.</param>
        /// <returns></returns>
        [OperationContract]
        [FaultContract(typeof(RemoteProviderFault))]
        PageVersion LoadVersion(PageReference pageLink);

        /// <summary>
        /// Loads the published version.
        /// </summary>
        /// <param name="pageLink">The page link.</param>
        /// <param name="languageBranch">The language branch.</param>
        /// <returns></returns>
        [OperationContract]
        [FaultContract(typeof(RemoteProviderFault))]
        PageVersion LoadPublishedVersion(PageReference pageLink, string languageBranch);

        /// <summary>
        /// Lists the delayed publish.
        /// </summary>
        /// <returns></returns>
        [OperationContract]
        [FaultContract(typeof(RemoteProviderFault))]
        RemotePageRaw[] ListDelayedPublish();

        /// <summary>
        /// Get collection of references to these pages
        /// </summary>
        /// <param name="pageLinks"></param>
        /// <returns></returns>
        [OperationContract]
        [FaultContract(typeof(RemoteProviderFault))]
        PageReferenceCollection GetReferencesToPages(PageReferenceCollection pageLinks);


        #endregion

        #region Remote Virtual Path Provider Operation

        /// <summary>
        /// Initializes the virtual path proivder.
        /// </summary>
        /// <param name="remoteVirtualPathProvidersInfo">The remote virtual path providers info.</param>
        [OperationContract]
        void InitializeVirtualPathProivder(ref RemoteVirtualPathProvidersInfo remoteVirtualPathProvidersInfo);

        /// <summary>
        /// Opens the specified virtualpath.
        /// </summary>
        /// <param name="virtualpath">The virtualpath.</param>
        /// <param name="remoteFileInfo">The remote file info.</param>
        [OperationContract]
        void Open(string virtualpath, out RemoteFileInfo remoteFileInfo);


        /// <summary>
        /// Files the exists.
        /// </summary>
        /// <param name="virtualPath">The virtual path.</param>
        /// <returns></returns>
        [OperationContract]
        bool FileExists(string virtualPath);

        /// <summary>
        /// Directories the exists.
        /// </summary>
        /// <param name="virtualPath">The virtual path.</param>
        /// <returns></returns>
        [OperationContract]
        bool DirectoryExists(string virtualPath);

        /// <summary>
        /// Gets the file.
        /// </summary>
        /// <param name="virtualPath">The virtual path.</param>
        /// <param name="remoteFileInfo">The remote file info.</param>
        /// <returns></returns>
        [OperationContract]
        bool GetFile(string virtualPath, out RemoteFileInfo remoteFileInfo);

        /// <summary>
        /// Gets the directory.
        /// </summary>
        /// <param name="virtualPath">The virtual path.</param>
        /// <param name="remoteDirectoryInfo">The remote directory info.</param>
        /// <returns></returns>
        [OperationContract]
        bool GetDirectory(string virtualPath, out RemoteDirectoryInfo remoteDirectoryInfo);

        /// <summary>
        /// Directorieses the specified virtualpath.
        /// </summary>
        /// <param name="virtualpath">The virtualpath.</param>
        /// <returns></returns>
        [OperationContract]
        RemoteDirectoryInfo[] Directories(string virtualpath);

        /// <summary>
        /// Fileses the specified virtualpath.
        /// </summary>
        /// <param name="virtualpath">The virtualpath.</param>
        /// <returns></returns>
        [OperationContract]
        RemoteFileInfo[] Files(string virtualpath);

        /// <summary>
        /// Resolves the file by virtual path.
        /// </summary>
        /// <param name="virtualpath">The virtualpath.</param>
        /// <param name="guid">The GUID.</param>
        /// <returns></returns>
        [OperationContract]
        string ResolveFileByVirtualPath(string virtualpath, out Guid guid);

        /// <summary>
        /// Resolves the file by GUID.
        /// </summary>
        /// <param name="guid">The GUID.</param>
        /// <returns></returns>
        [OperationContract]
        string ResolveFileByGuid(Guid guid);
        #endregion

        #region Communication 
        /// <summary>
        /// Gets the state of the communication.
        /// </summary>
        /// <returns></returns>
        CommunicationState GetCommunicationState();
        #endregion
    }


}
